What is global-dirs?
The global-dirs npm package is designed to provide information about the directories used by npm and Yarn for global installations. This can include paths to globally installed packages, binaries, and more. It's particularly useful for tooling and applications that need to interact with or manage globally installed npm or Yarn packages.
What are global-dirs's main functionalities?
Accessing npm and Yarn global directories
This feature allows you to access the paths to the global installation directories of npm and Yarn. This can be useful for tools that need to know where global packages are installed.
const globalDirs = require('global-dirs');
console.log(globalDirs.npm.prefix); // Path to npm's global installation directory
console.log(globalDirs.yarn.prefix); // Path to Yarn's global installation directory
Accessing npm and Yarn global binaries directories
This feature provides the paths to the directories where npm and Yarn store globally installed binaries. This is useful for executing global binaries or for tools that manage global packages and their executables.
const globalDirs = require('global-dirs');
console.log(globalDirs.npm.binaries); // Path to npm's global binaries directory
console.log(globalDirs.yarn.binaries); // Path to Yarn's global binaries directory
Other packages similar to global-dirs
find-global-packages
Similar to global-dirs, find-global-packages is focused on identifying globally installed npm packages. However, it goes a step further by listing the packages themselves, not just the directories where they are installed. This makes it more suited for applications that need to inspect or interact with the installed packages directly.
global-modules
global-modules provides the path to the global npm modules directory, similar to one aspect of global-dirs. The main difference is that global-modules is specifically focused on the modules directory for npm, without providing additional context for Yarn or other types of global directories.
global-dirs
Get the directory of globally installed packages and binaries
Uses the same resolution logic as npm
and yarn
.
Install
$ npm install global-dirs
Usage
const globalDirectories = require('global-dirs');
console.log(globalDirectories.npm.prefix);
console.log(globalDirectories.npm.packages);
console.log(globalDirectories.npm.binaries);
console.log(globalDirectories.yarn.packages);
API
globalDirectories
npm
yarn
packages
Directory with globally installed packages.
Equivalent to npm root --global
.
binaries
Directory with globally installed binaries.
Equivalent to npm bin --global
.
prefix
Directory with directories for packages and binaries. You probably want either of the above.
Equivalent to npm prefix --global
.
Related